﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CommonTools.UserControls.FlowChart
{
    /// <summary>
    /// FlowItemControl.xaml 的交互逻辑
    /// </summary>
    public partial class FlowItemControl : FlowBaseControl
    {


        public FlowItemModel Info
        {
            get { return (FlowItemModel)GetValue(InfoProperty); }
            set { SetValue(InfoProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Info.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty InfoProperty =
            DependencyProperty.Register("Info", typeof(FlowItemModel), typeof(FlowItemControl), new PropertyMetadata(null, (sender, e)=>
            {
                var dp = sender as FlowItemControl;
                if (dp == null) return;
                dp.GetInfo();
            }));



        public bool LinkPreview
        {
            get { return (bool)GetValue(LinkPreviewProperty); }
            set { SetValue(LinkPreviewProperty, value); }
        }

        // Using a DependencyProperty as the backing store for LinkPreview.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty LinkPreviewProperty =
            DependencyProperty.Register("LinkPreview", typeof(bool), typeof(FlowItemControl), new PropertyMetadata(false));



        public double ScaleValue
        {
            get { return (double)GetValue(ScaleValueProperty); }
            set { SetValue(ScaleValueProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ScaleValue.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ScaleValueProperty =
            DependencyProperty.Register("ScaleValue", typeof(double), typeof(FlowItemControl), new PropertyMetadata(1.0));




        public FlowItemControl()
        {
            InitializeComponent();
        }

        private void GetInfo()
        {
            if (Info == null) return;
            Info.PropertyChanged += Info_PropertyChanged;
        }

        private void Info_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            switch (e.PropertyName) 
            {
                case "X":
                    Canvas.SetLeft(this, Info.X);
                    break;
                case "Y":
                    Canvas.SetTop(this, Info.Y);
                    break;
            }
        }
    }
}
